<template  >
  <div class="all">
    <!-- 页头 -->
    <el-container class="allContainer">
      <el-header class="head">
        <div class="divHead"></div>
        <el-row>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <div>
                <div class="topFont">合同签订管理</div>
              </div>
            </div>
          </el-col>
          <div class="divBtn">
            <el-button size="mini" type="primary" icon="el-icon-edit" @click="carsAdd">新增</el-button>

            <el-dialog title="合同新增" :visible.sync="dialogAddgsVisible" @close="closeDialogAddgsVisible">
              <div class="dialogAll">
                <div class="left">
                  <div class="leftFont">合同基本信息：</div>

                  <div class="leftForm">
                    <div class="visitorForm">
                      <el-form ref="visitorForm" label-width="80px" size="mini" :model="addContract">
                        <el-form-item label="合同编号" :required="false" style="width: 250px" prop="contractNum">
                          <el-input v-model="addContract.contractNum" autocomplete="off">
                          </el-input>
                        </el-form-item>
                        <el-form-item label="签订时间" :required="false" style="width: 250px" prop="contractRenewal">
                          <el-input v-model="addContract.contractRenewal" autocomplete="off"
                            placeholder="日期格式：yyyy-MM-dd">
                          </el-input>
                        </el-form-item>
                        <el-form-item label="结束时间" :required="false" style="width: 250px" prop="contractExpire">
                          <el-input v-model="addContract.contractExpire" autocomplete="off"
                            placeholder="日期格式：yyyy-MM-dd">
                          </el-input>
                        </el-form-item>
                        <el-form-item label="租户名称" :required="false" style="width: 250px" prop="enterpriseName">
                          <el-input v-model="addContract.enterpriseName" autocomplete="off">
                          </el-input>
                        </el-form-item>

                        <el-form-item label="合同属性" :required="false" style="width: 250px" prop="contractAtt">
                          <el-input v-model="addContract.contractAtt" autocomplete="off">
                          </el-input>
                        </el-form-item>

                        <el-form-item label="签订人" :required="false" style="width: 250px" prop="staffsName">
                          <el-input v-model="addContract.staffsName" autocomplete="off">
                          </el-input>
                        </el-form-item>
                        <el-form-item label="联系方式" :required="false" style="width: 250px" prop="staffsTel">
                          <el-input v-model="addContract.staffsTel" autocomplete="off">
                          </el-input>
                        </el-form-item>
                      </el-form>
                    </div>
                  </div>
                </div>

                <div class="right">
                  <div class="rightFont">其他信息</div>
                  <div class="rightForm">
                    <div class="carForm">
                      <el-form ref="visitorForm" label-width="80px" size="mini" :model="addContract">
                        <el-form-item label="所属楼宇" :required="false" style="width: 250px; float: left"
                          prop="buildingName">
                          <el-input v-model="addContract.buildingName" autocomplete="off">
                          </el-input>
                        </el-form-item>

                        <el-form-item label="房间名称" :required="false" style="width: 250px; float: left" prop="roomName">
                          <el-input v-model="addContract.roomName" autocomplete="off">
                          </el-input>
                        </el-form-item>

                        <el-form-item label="开户名称" :required="false" style="width: 250px; float: left"
                          prop="enterpriseCreditcode">
                          <el-input v-model="addContract.enterpriseCreditcode" autocomplete="off">
                          </el-input>
                        </el-form-item>

                        <el-form-item label="银行卡号" :required="false" style="width: 250px; float: left"
                          prop="contractBy2">
                          <el-input v-model="addContract.contractBy2" autocomplete="off">
                          </el-input>
                        </el-form-item>
                        <el-form-item label="收款金额" :required="false" style="width: 250px; float: left"
                          prop="informationMoney">
                          <el-input v-model="addContract.informationMoney" autocomplete="off">
                          </el-input>
                        </el-form-item>
                      </el-form>
                    </div>
                  </div>
                </div>
              </div>

              <div slot="footer" style="text-align: center">
                <el-button @click="dialogAddgsVisible = false">取 消</el-button>
                <el-button type="primary" @click="addContracts()">确 定</el-button>
              </div>
            </el-dialog>
            <el-button size="mini" type="warning" icon="el-icon-delete">批量删除</el-button>
          </div>
        </el-row>
      </el-header>
      <el-main class="bottomMain">
        <div class="divMain">
          <template>
            <!-- 模糊查询 -->
            <div class="mainTop">
              <div class="divInputAll">
                <!-- 输入框 -->
                <div class="divInput">
                  <div class="inputFont">租户名称：</div>
                  <div style="float: left">
                    <el-input size="mini" placeholder="请输入租户名称" v-model="queryContracts.enterpriseName">
                    </el-input>
                  </div>
                </div>
                <div class="divInput">
                  <div class="inputFont">所属楼宇：</div>
                  <div style="float: left">
                    <el-input size="mini" placeholder="请输入楼宇名称" v-model="queryContracts.buildingName">
                    </el-input>
                  </div>
                </div>

                <div class="divInput">
                  <div class="inputFont">房间名称：</div>
                  <div style="float: left">
                    <el-input size="mini" placeholder="请输入房间名称" v-model="queryContracts.roomName">
                    </el-input>
                  </div>
                </div>

                <div class="likeBtn">
                  <el-button
                    size="mini"
                    type="success"
                    icon="el-icon-search"
                    @click="LikeLoadContracts"
                    >查询</el-button
                  >
                  <el-button size="mini" plain @click="loadContractsNull"
                    >重置</el-button
                  >
                </div>
              </div>
            </div>
          </template>

          <!------------------------------------ 查所有合同,表格 -------------------------------->
          <div class="divSelAll">
            <template>
              <el-table :data="contractList" border style="width: 100%; font-size: x-small; margin: auto"
                :row-style="{ height: '22px' }" :cell-style="{ padding: '1px' }">
                <el-table-column fixed type="selection" prop="contractId" width="50">
                </el-table-column>

                <el-table-column fixed prop="enterpriseName" label="租户名称" width="210">
                </el-table-column>
                <el-table-column prop="buildingName" label="所属楼宇" width="70">
                </el-table-column>
                <el-table-column prop="roomName" label="房间名称" width="80">
                </el-table-column>
                <el-table-column prop="contractAtt" label="合同类型" width="70">
                </el-table-column>
                <el-table-column prop="contractState" label="合同状态" width="70">
                </el-table-column>
                <el-table-column prop="contractRenewal" label="签约时间" width="200">
                </el-table-column>
                <el-table-column prop="contractExpire" label="到期时间" width="200s">
                </el-table-column>

                <el-table-column label="操作" width="210">
                  <template slot-scope="scope">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">详情</el-button>
                    <el-button type="text" size="small">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </div>
          <div class="divPage">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
              :current-page="queryContracts.currentPage" :page-sizes="[5, 10, 30, 50]"
              :page-size="queryContracts.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="page.total">
            </el-pagination>
          </div>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //模态框
      dialogAddgsVisible: false,
      //新增企业合同
      addContract: {},
      contractList: [],
      addDialog: false,
      page: {
        total: 0, //总条数
      },

      //分页
      queryContracts: {
        currentPage: 1, //当前页
        pageSize: 5, //每页显示的条数
        enterpriseName: "", //住户名称
        buildingName: "", //楼宇名称
        roomName: "", //房间名称
      },

      //日期
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
    };
  },
  mounted() {
    this.loadContracts();
  },

  methods: {
    LikeLoadContracts(){
      this.queryContracts.currentPage=1,
      this.loadContracts();
    },
    loadContractsNull() {
      (this.queryContracts.enterpriseName = ""), //住户名称
        (this.queryContracts.buildingName = ""), //楼宇名称
        (this.queryContracts.roomName = ""), //房间名称
        this.loadContracts();
    },
    //每一页显示的条数变化时
    handleSizeChange(val) {
      this.queryContracts.pageSize = val;
      this.loadContracts();
    },
    //当前页数变化时
    handleCurrentChange(val) {
      this.queryContracts.currentPage = val;
      this.loadContracts();
    },
    /**
     *点击新增按钮，弹出新增模态框
     */
    carsAdd() {
      this.dialogAddgsVisible = true;
    },
    contractsInformation() {
      this.dialogAddgsVisible = true;
    },
    /**
     * 获取全部合同
     */
    loadContracts() {
      this.$axios.post("contracts/selectAlls", this.queryContracts).then((res) => {
        this.contractList = res.data.data.contractList;
        this.page.total = res.data.data.total;
      });
    },
    addContracts() {
      this.$axios.post("contracts/insertDTO", this.addContract).then((res) => {
        if (res.data.code == 200) {
          this.dialogAddgsVisible = false;
          this.$message.success("添加成功");
          // this.addDialog = false; //关闭dialog
          this.loadContracts();
          this.$refs.addEnterprise.resetFields(); //重置form
        }
      });
    },

    /**
     *关闭或取消模态框，清空asdsadad值
     */
    // closeDialogAddgsVisible(){
    //   this.$refs.from.resetFields();//element封装的方法,清空模态框的值
    //   this.from={//初始化from中的值
    //   }
    // },
  },
};
</script>
<style >
.all {
  width: 100%;
  height: 700px;
  background-color: rgb(240, 242, 245);
}

.allContainer {
  width: 98%;
  margin: auto;
}

.head {
  background-color: white;
  width: 100%;
  height: 10px;
  line-height: 60px;
  margin: auto;
  border-radius: 10px;
  margin-top: 5px;
}

.divHead {
  background-color: cornflowerblue;
  width: 7px;
  height: 50%;
  float: left;
  margin-top: 15px;
  border-radius: 2px;
  margin-left: 8px;
}

.topFont {
  float: left;
  margin-left: 18px;
  font-size: 14px;
  font-weight: 900;
}

.divBtn {
  float: right;
  margin-right: 10px;
}

.bottomMain {
  border-radius: 8px;
  width: 100%;
  height: 620px;
  margin: auto;
  margin-top: 5px;
}

.divMain {
  width: 100%;
  height: 100%;
}

.mainTop {
  width: 100%;
  height: 13%;
  margin: auto;
  border: 1px solid darkgray;
  border-radius: 5px;
}

.divInputAll {
  background-color: rgb(255, 255, 255);
  width: 100%;
  height: 60px;
  line-height: 40px;
  margin: auto;
  border-radius: 10px;
  margin-top: 5px;
}

/** 搜索栏div */
.divInput {
  border: 0px solid red;
  width: 20%;
  height: 100%;
  line-height: 60px;
  margin-left: 30px;
  float: left;
}

.divSelect {
  border: 0px solid red;
  width: 24.9%;
  height: 100%;
  line-height: 60px;
  margin-left: 30px;
  float: left;
}

.likeBtn {
  float: right;
  margin-right: 12px;
  line-height: 60px;
}

.inputFont {
  float: left;
  font-size: 11px;
}

.optionFont {
  float: right;
  color: #8492a6;
  font-size: xx-small;
}

.divSelAll {
  width: 100%;
  height: 72%;
  margin-top: 10px;
  line-height: 23px;
}

.divPage {
  width: 100%;
  height: 2%;
  margin-top: 20px;
  line-height: 10px;
}

.el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 54%;
  left: 57.5%;
  transform: translate(-50%, -50%);
  height: 700px;
  width: 1135px;
  max-height: calc(100% - 30px);
  max-width: calc(100% - 30px);
}

.el-dialog .el-dialog__body {
  flex: 1;
  overflow: auto;
}

.dialogAll {
  border: 0px solid red;
  width: 98%;
  height: 105%;
  margin: auto;
  margin-top: -30px;
}

.left {
  border: 0px solid red;
  width: 50%;
  height: 100%;
  float: left;
}

.right {
  border: 0px solid red;
  width: 50%;
  height: 100%;
  float: right;
}

.leftFont,
.rightFont {
  border: 0px solid red;
  width: 90%;
  height: 5%;
  line-height: 20px;
  text-align: left;
  font-weight: 500;
  font-family: "微软楷体";
  margin-left: 10px;
}

.leftForm,
.rightForm {
  border: 2px dashed #8492a6;
  border-radius: 10px;
  width: 80%;
  height: 94%;
}

.visitorForm,
.carForm {
  border: 0px solid red;
  width: 90%;
  height: 95%;
  margin: auto;
  margin-top: 30px;
  margin-left: 15px;
}
</style>
